var baseUrl = 'http://api.piver.cn/index.php?route=';

global.RouteMap = {
  'home':baseUrl+ 'module/banner',
  'reg':baseUrl+'account/register/test',
  'sendcode':baseUrl + 'account/sendcode',
  'login2':baseUrl + 'account/login/test',
  'forgetpassword':baseUrl + 'account/forgetpassword',
  'forgetpasswordconfirm':baseUrl + 'account/forgetpassword/confirm',
  'smslogin':baseUrl + 'account/login/sms',
  'category':baseUrl + 'product/category/test',
  'categorysub':baseUrl + 'category/sub',
  'brandList':baseUrl + 'brand/list',
  'categoryList':baseUrl + 'product/category/test',
  'productDetail':baseUrl + 'product/product',
  'cardAdd':baseUrl + 'checkout/cart/add',
  'checkoutCart':baseUrl + 'checkout/cart',
  'payment_surplus':baseUrl + 'checkout/checkout',
  'confirmPay':baseUrl + 'checkout/confirm',
  'delAddress':baseUrl + 'account/address/del',
  'getAddress':baseUrl + 'checkout/shipping_address',
  'addaddress':baseUrl + 'account/address/add',
  'editaddress':baseUrl + 'account/address/edit',
  'changephone':baseUrl + 'account/edit/phone',
  'changePass':baseUrl + 'account/edit/password',
  'changeSignature': baseUrl + 'account/edit/signature',
  'accountEdit':baseUrl + 'account/edit',
  'cardRemove':baseUrl + 'checkout/cart/remove',
  'attrList':baseUrl + 'product/attr/lists',
  'addconsignment':baseUrl + 'consignment/add',
  'imgUpload':baseUrl + 'tool/upload',
  'getContents':baseUrl + 'article/index',
  'getContentsArticle':baseUrl + 'article/index/detail',
  'hotSearch':baseUrl + 'search/index',
  'wishListUsers':baseUrl + 'account/wishlist/users',
  'wishlistAdd':baseUrl + 'account/wishlist/add',
  'wishlistRemove':baseUrl + 'account/wishlist/remove',
  'wishlistGet':baseUrl + 'account/wishlist',
  'peopleDetail':baseUrl + 'account/detail',

  'searchAll':baseUrl + 'search/index/findKeyword',
  'searchArticle':baseUrl + 'search/index/findKeywordMore',
  'comments':baseUrl + 'comment/lists',
  'commentAdd':baseUrl + 'comment/add',
  'meFans':baseUrl + 'account/fans/fansnum',
  'meFansList':baseUrl + 'account/fans/fans',
  'meFollowList':baseUrl + 'account/fans/followers',
  'mefollow':baseUrl + 'account/fans/follownum',
  'zan':baseUrl + 'account/like/like',
  'cancelZan':baseUrl + 'account/like/unlike',
  'articleSc':baseUrl + 'article/favors/add',
  'articleScRemove':baseUrl + 'article/favors/remove',
  'notify':baseUrl + 'notify/newly',
  'photoupload':baseUrl + 'account/avatar',
  'allorder':baseUrl + 'account/order',
  'awaitorder':baseUrl + 'account/order/await',
  'shipmentorder':baseUrl + 'account/order/shipment',

  'receivedorder':baseUrl + 'account/order/received',
  'unevaluatedorder':baseUrl + 'account/order/unevaluated',
  'getOrderInformation':baseUrl + 'account/order/express',
  'getMsgDiscuss':baseUrl + 'comment/newly',
  'getMsgNews':baseUrl + 'notify/newly',
  'getMsgFans':baseUrl + 'account/fans/newly',
  'getUnReadNum':baseUrl + 'comment/unread',
  'getUnReadNewsNum':baseUrl + 'notify/newly/newlynum',
  'getNewFansNum':baseUrl + 'account/fans/newlynum',
  'quxiaoOrder':baseUrl + 'account/order/cancel',
  'tixingOrder':baseUrl + 'account/order/remind',
  'shouhuoOrder':baseUrl + 'account/order/confirm',
  'removeOrder':baseUrl + 'account/order/remove',
  'meSaleAll':baseUrl + 'consignment/product',
  'peoplePurse':baseUrl + 'wallet/index/myMoney',
  'otherPeople':baseUrl + 'account/user',
  'otherPeopleShop':baseUrl + 'consignment/product',
  'followPeople':baseUrl + 'account/fans/follow',
  'unfollowPeople':baseUrl + 'account/fans/unfollow',
  'OneOrder':baseUrl + 'account/order/info',
  'cartNum':baseUrl + 'checkout/cart/cartNum',
  'getqr':baseUrl + 'consignment/qr',
  'products':baseUrl + 'product/products',
  'tixian':baseUrl + 'wallet/index/addCash',
  'bannerList':baseUrl + 'module/banner/view&id=15',
  'categoryView':baseUrl + 'category/view',
  'sjaddress':baseUrl + 'module/address',
  'shopinfo':baseUrl + 'shopinfo/index',
  'orderpayment':baseUrl + 'account/order/payment',
	'myMessage': baseUrl + 'chat/newly',
  'share':baseUrl + 'common/share',
  'wxopenid':baseUrl + 'account/wxopenid',
  'consignmentGetList':baseUrl + 'consignment/product/getList',
  'consignmentShelves':baseUrl + 'consignment/shelves',
  'consignmentAdd':baseUrl + 'consignment/express/add',
  'information':baseUrl + 'information/information',
  'messageTalk':baseUrl + 'chat/sync',
  'chartNum':baseUrl + 'chat/num'

};

global.utilities = {
  timer:null,
  timer1:null,
  guid: function () {
    function s4() {
      return Math.floor((1 + Math.random()) * 0x10000)
        .toString(16)
        .substring(1);
    }
    return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
      s4() + '-' + s4() + s4() + s4();
  },
  envSense: function() {
    var ua = window.navigator.userAgent.toLowerCase();
    return {
      app: /yrlc/i.test(ua), //是否客户端,
      wechat: /micromessenger/i.test(ua), //是否为微信
      ios: !!ua.match(/\(i[^;]+;( u;)? cpu.+mac os x/), //ios移动端
      android: /android/i.test(ua), //android移动端
      mobile: /applewebkit.*mobile.*/.test(ua)

      // !!ua.match(/applewebkit.*mobile.*/), //是否为移动终端
    }
  },
  getUrlParameter: function (name) {
    var url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
      results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
  },
  isMobile: function (mobile) {
    return /^1[3|4|5|8|7][0-9]\d{8}$/.test(mobile);
    // return /^[\d]{11}$/.test(mobile);
  },
  isEmail: function (email) {
    return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(email);
  },
  isString:function(str){
    return typeof(str) == 'string';
  },
  isCaptchaValid: function (captcha) {
    return this.isString(captcha) && captcha.length >= 4;
  },
  isSmsCodeValid: function (code) {
    return this.isString(code) && code.length >= 4;
  },
  isPasswordValid: function (password) {
    return this.isString(password) && password.length >= 6 && password.length <= 20;
  },
  isPasswordValidRegister: function (password) {

    return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/.test(password);

  },
  isNull(str){
			if (typeof str == "undefined") {
				return true;
			} else if (str == null) {
				return true;
			} else if (typeof str == "string" && (str === "" || str === "undefined" || str === "null")) {
				return true;
			} else if (typeof str == "object" && $.isArray(str) && str.length == 0) {
				return true;
			} else if (typeof str == "object" && $.isEmptyObject(str)) {
				return true;
			} else {
				return false;
			}
	},
  setCookie: function (name,value,days){
    var Days = days || 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ encodeURI(value) + ";expires=" + exp.toGMTString();
  },
  getCookie: function (name)
  {
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)){
      return decodeURI(arr[2]);
    }
    else{
      return null;
    }
  }
}
